package com.hxzy.controller.unit;

import com.alibaba.fastjson.JSONObject;
import com.hxzy.util.ThreadLocalUtil;
import com.hxzy.common.BaseServlet;
import com.hxzy.common.ResultAjax;
import com.hxzy.entity.Unit;
import com.hxzy.service.UnitService;
import com.hxzy.service.impl.UnitServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @Author: lqq
 * @Description:
 * @Date: 2022/3/9 14:42
 */
@WebServlet(urlPatterns = "/unit/findId")
public class SearchServletById extends BaseServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        try {
            ThreadLocalUtil.threadLocal.get();
            Unit unit=super.CollectiongParameterVlues(req,Unit.class);
           UnitService unitService =new UnitServiceImpl();
            int i = unitService.findById(unit);
            ResultAjax resultAjax=ResultAjax.success();
            if (i>0){
                resultAjax.put(resultAjax.DATA,"该单元已存在");
            }
            super.render(resp, JSONObject.toJSONString(resultAjax));
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }
    }
}
